{extend name="/base"/}
{block name="html"}
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
    <legend>增加博客</legend>
</fieldset>
<form class="layui-form" action="">
    <div class="layui-form-item">
        <label class="layui-form-label">标题</label>
        <div class="layui-input-block">
            <input id="title" style="width: 500px" type="text" name="title" required lay-verify="required"
                   placeholder="请输入标题" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">链接</label>
        <div class="layui-input-block">
            <input id="link" style="width: 500px" type="text" name="link" required lay-verify="required"
                   placeholder="请输入标题" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button onclick="add()" class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>
{/block}

{block name="js"}

<script>
    $("#add-item").attr("class", "layui-this")

    function add() {
        var title = $("#title").val()
        var link = $("#link").val()

        if (title == "" || link == "") {
            alert("信息不完整");
            return
        }

        $.ajax({
                url: "{:url('blog/addBlog')}",
                data: {title: title, link: link},
                success: function (data) {
                    if (data.code == 1) {
                        alert("添加成功！");
                    } else {
                        alert("添加失败！");
                    }
                }
            }
        )
    }
</script>
{/block}